﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Simple.Common.Helpers
{
    public static class AgeHelper
    {
        public static string ToAgeStr(DateTime birthday)
        {
            var birYear = birthday.Year;
            var birMonth = birthday.Month;
            var birDay = birthday.Day;
            var nowYear = DateTime.Now.Year;
            var nowMonth = DateTime.Now.Month;
            var nowDay = DateTime.Now.Day;
            var year = nowYear - birYear;
            var month = nowMonth - birMonth;
            if (nowMonth < birMonth || (nowMonth == birMonth && nowDay < birDay))
            {
                year--;
                month += 12;
            }
            var result = (year > 0 ? year + "岁" : "") + (month > 0 ? month + "个月" : "");
            if (year <= 0 && month <= 0)
            {
                result = "未满月";
            }
            return result;
        }
    }
}
